﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LIMS.Web
{
    public partial class InfoLab : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddlOrderDate.DataSource = BLL.LabManager.GetAllOrderDate();
                ddlOrderDate.DataTextFormatString = "{0:yyyy-MM-dd}";
                ddlOrderDate.DataBind();
                ddlOrderDate.Items.Insert(0, new ListItem("选择所有数据"));

                rpLab.DataSource = BLL.LabManager.GetAllLabInfo();
                rpLab.DataBind();

                AspNetPager1.RecordCount = BLL.LabManager.GetAllLabInfo().Count;
                rpLab.DataSource = Common.CommonPager<Model.Labs>.GetTSourceByPager(BLL.LabManager.GetAllLabInfo(), AspNetPager1.PageSize, 1);
                rpLab.DataBind();
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rpLab.DataSource = Common.CommonPager<Model.Labs>.GetTSourceByPager(BLL.LabManager.GetAllLabInfo(), AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
            rpLab.DataBind();
        }

        /// <summary>
        /// 将True或者False这样类型的值转换为“是”或者“否”
        /// </summary>
        /// <param name="objBoolType"></param>
        /// <returns></returns>
        protected String ConvertBoolToString(object objBoolType)
        {
            Boolean tmp = false;

            return (objBoolType == null
                        || String.IsNullOrWhiteSpace(objBoolType.ToString())
                        || !Boolean.TryParse(objBoolType.ToString(), out tmp)
                        || Boolean.Parse(objBoolType.ToString()) != true) ? "否" : "是";
        }

        /// <summary>
        /// 预约日期改变，选择出相应日期下的实验室预约数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlOrderDate_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlOrderDate.SelectedIndex != 0)
            {
                rpLab.DataSource = BLL.LabManager.GetLabsByOrderDate(DateTime.Parse(ddlOrderDate.SelectedValue).Date);
                rpLab.DataBind();
            }
            else
            {
                rpLab.DataSource = BLL.LabManager.GetAllLabInfo();
                rpLab.DataBind();
            }
        }

        protected void btnlog4netDemo_Click(object sender, EventArgs e)
        {
            //创建日志记录组件实例
            log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //记录错误日志
            log.Error("error", new Exception("发生了一个异常！"));

            //记录严重错误
            log.Fatal("fatal", new Exception("发生了致命的错误！" + "\r\n"));

            //记录一般的信息
            log.Info("info", new Exception("一般的信息"));

            //记录调试信息
            log.Debug("debug");

            //记录警告信息
            log.Warn("warn");

            Response.Write("日志记录完毕。\n");
        }

    }
}